<?php

namespace app\api\controller;

use app\admin\model\order\Spelldetail;
use app\common\controller\Api;
use fast\Http;
use fast\Utils;
use think\Db;
use think\Exception;

/**
 * 会员信息接口
 */
class Share extends Api
{
    protected $noNeedLogin = '*';
    public function _initialize()
    {
        parent::_initialize();
    }

    public function spellOrder(){
        header("access-control-allow-headers:*");
        header("access-control-allow-methods:*");
        header("access-control-allow-origin:*");
        $ptid = $this->request->request("ptid",0);
        $invCode = $this->request->request("inviteCode",0);
        $orderInfo = \app\admin\model\SpellOrder::where('id',$ptid)->where('payStatus',1)->where('orderStatus',2)->find();
        if(empty($orderInfo)) $this->error('该拼团不存在');
        $ptinfo = \app\admin\model\spell\Spell::where('orderId',$orderInfo['orderId'])->find();
        $ptinfo['goodsInfo']=(new Spelldetail)->field('id,goodsId,goodsName,image,price')->where(['orderId'=>$ptinfo['orderId']])->select();
        $spellList = (new \app\admin\model\spell\Spell)->where('ptid',$ptinfo['ptid'])->order('id asc')->field('mobile,avatar,price')->select();
        $ptinfo['spellList'] = !empty($spellList)?$spellList:[];
        $ptinfo['regurl']='http://pt-img.sdgjjy.com/share/index.html?inviteCode='.$invCode."&ptid=".$ptid;
        $ptinfo['regurl']=Utils::getShortUrl($ptinfo['regurl']);
        $ptinfo['inviteCode']=base64_decode($invCode);
        $this->success('ok',$ptinfo);
    }

    public function telAddr(){
        header("access-control-allow-headers:*");
        header("access-control-allow-methods:*");
        header("access-control-allow-origin:*");
        $mobile=$this->request->request("mobile",0);
        $res=\fast\Utils::xml2array(\fast\Http::get("https://v.showji.com/Locating/showji.com20180331.aspx?m={$mobile}"));
        $this->success('ok',$res);

    }


}
